#include "SeqList.h"
#include <assert.h>

void testInit()
{
  SeqList list;
  SeqListInit(&list);
  assert(list.a == NULL);
  assert(list.size == 0);
  assert(list.capacity == 0);
  printf("Init test passed.\n");
}

void testDestroy()
{
  SeqList list;
  SeqListInit(&list);
  SeqListPushBack(&list, 1);
  SeqListDestroy(&list);
  assert(list.a == NULL);
  assert(list.size == 0);
  assert(list.capacity == 0);
  printf("Destroy test passed.\n");
}

void testPushBack()
{
  SeqList list;
  SeqListInit(&list);
  SeqListPushBack(&list, 1);
  SeqListPushBack(&list, 2);
  SeqListPushBack(&list, 3);
  assert(list.size == 3);
  assert(list.a[0] == 1);
  assert(list.a[1] == 2);
  assert(list.a[2] == 3);
  SeqListDestroy(&list);
  printf("PushBack test passed.\n");
}

void testPushFront()
{
  SeqList list;
  SeqListInit(&list);
  SeqListPushFront(&list, 1);
  SeqListPushFront(&list, 2);
  SeqListPushFront(&list, 3);
  assert(list.size == 3);
  assert(list.a[0] == 3);
  assert(list.a[1] == 2);
  assert(list.a[2] == 1);
  SeqListDestroy(&list);
  printf("PushFront test passed.\n");
}

void testPopBack()
{
  SeqList list;
  SeqListInit(&list);
  SeqListPushBack(&list, 1);
  SeqListPushBack(&list, 2);
  SeqListPushBack(&list, 3);
  SeqListPopBack(&list);
  assert(list.size == 2);
  assert(list.a[0] == 1);
  assert(list.a[1] == 2);
  SeqListPopBack(&list);
  SeqListPopBack(&list);
  assert(list.size == 0);
  SeqListDestroy(&list);
  printf("PopBack test passed.\n");
}

void testPopFront()
{
  SeqList list;
  SeqListInit(&list);
  SeqListPushBack(&list, 1);
  SeqListPushBack(&list, 2);
  SeqListPushBack(&list, 3);
  SeqListPopFront(&list);
  assert(list.size == 2);
  assert(list.a[0] == 2);
  assert(list.a[1] == 3);
  SeqListPopFront(&list);
  SeqListPopFront(&list);
  assert(list.size == 0);
  SeqListDestroy(&list);
  printf("PopFront test passed.\n");
}

void testFind()
{
  SeqList list;
  SeqListInit(&list);
  SeqListPushBack(&list, 1);
  SeqListPushBack(&list, 2);
  SeqListPushBack(&list, 3);
  assert(SeqListFind(&list, 2) == 1);
  assert(SeqListFind(&list, 4) == -1);
  SeqListDestroy(&list);
  printf("Find test passed.\n");
}

void testInsert()
{
  SeqList list;
  SeqListInit(&list);
  SeqListInsert(&list, 0, 1);
  assert(list.size == 1);
  assert(list.a[0] == 1);
  SeqListInsert(&list, 1, 3);
  assert(list.a[1] == 3);
  SeqListInsert(&list, 1, 2);
  assert(list.size == 3);
  assert(list.a[0] == 1);
  assert(list.a[1] == 2);
  assert(list.a[2] == 3);
  SeqListDestroy(&list);
  printf("Insert test passed.\n");
}

void testErase()
{
  SeqList list;
  SeqListInit(&list);
  SeqListPushBack(&list, 1);
  SeqListPushBack(&list, 2);
  SeqListPushBack(&list, 3);
  SeqListErase(&list, 1);
  assert(list.size == 2);
  assert(list.a[0] == 1);
  assert(list.a[1] == 3);
  SeqListErase(&list, 0);
  assert(list.a[0] == 3);
  SeqListErase(&list, 0);
  assert(list.size == 0);
  SeqListDestroy(&list);
  printf("Erase test passed.\n");
}

void testCapacity()
{
  SeqList list;
  SeqListInit(&list);
  for (int i = 0; i < 10; i++)
  {
    SeqListPushBack(&list, i);
  }
  assert(list.size == 10);
  assert(list.capacity >= 10);
  for (int i = 0; i < 10; i++)
  {
    assert(list.a[i] == i);
  }
  SeqListDestroy(&list);
  printf("Capacity test passed.\n");
}

int main()
{
  testInit();
  testDestroy();
  testPushBack();
  testPushFront();
  testPopBack();
  testPopFront();
  testFind();
  testInsert();
  testErase();
  testCapacity();
  printf("All tests passed!\n");
  return 0;
}